package com.example.controller;

import com.example.entity.MedicalApproval;
import com.example.service.MedicalApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/medicalApproval")
public class MedicalApprovalController {

    @Autowired
    private MedicalApprovalService medicalApprovalService;

    // 创建审批记录
    @PostMapping("/add")
    public String addMedicalApproval(@RequestBody MedicalApproval approval) {
        medicalApprovalService.addMedicalApproval(approval);
        return "审批记录创建成功";
    }

    // 根据ID查询审批记录
    @GetMapping("/get/{id}")
    public MedicalApproval getMedicalApprovalById(@PathVariable int id) {
        return medicalApprovalService.getMedicalApprovalById(id);
    }

    // 查询所有审批记录
    @GetMapping("/all")
    public List<MedicalApproval> getAllMedicalApprovals() {
        return medicalApprovalService.getAllMedicalApprovals();
    }

    // 更新审批状态
    @PutMapping("/update")
    public String updateMedicalApproval(@RequestBody MedicalApproval approval) {
        medicalApprovalService.updateMedicalApproval(approval);
        return "审批记录更新成功";
    }

    // 删除审批记录
    @DeleteMapping("/delete/{id}")
    public String deleteMedicalApproval(@PathVariable int id) {
        medicalApprovalService.deleteMedicalApproval(id);
        return "审批记录删除成功";
    }
}
